cmake_minimum_required(VERSION 3.5)

project(orb_slam3)

LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules)

find_package(OpenCV 3.4)
if(NOT OpenCV_FOUND)
   message(FATAL_ERROR "OpenCV > 3.4 not found.")
endif()

MESSAGE("OPENCV VERSION:")
MESSAGE(${OpenCV_VERSION})

find_package(Boost REQUIRED COMPONENTS serialization)

find_package(Eigen3 3.1.0 REQUIRED)

link_directories(${PROJECT_LIBRARY_OUTPUT_PATH}
    ${STATIC_LIBRARY_OUTPUT_PATH})

include_directories(
${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/include/CameraModels
${THIRD_PATH}/Sophus
${EIGEN3_INCLUDE_DIR}
)

if(BUILD_TEST)
   find_package(Pangolin REQUIRED)
   include_directories(${Pangolin_INCLUDE_DIRS})
endif()

add_library(${PROJECT_NAME} SHARED
src/System.cc
src/Tracking.cc
src/LocalMapping.cc
src/LoopClosing.cc
src/ORBextractor.cc
src/ORBmatcher.cc
src/FrameDrawer.cc
src/Converter.cc
src/MapPoint.cc
src/KeyFrame.cc
src/Atlas.cc
src/Map.cc
src/MapDrawer.cc
src/Optimizer.cc
src/Frame.cc
src/KeyFrameDatabase.cc
src/Sim3Solver.cc
src/Viewer.cc
src/ImuTypes.cc
src/G2oTypes.cc
src/CameraModels/Pinhole.cpp
src/CameraModels/KannalaBrandt8.cpp
src/OptimizableTypes.cpp
src/MLPnPsolver.cpp
src/GeometricTools.cc
src/TwoViewReconstruction.cc
src/Config.cc
src/Settings.cc
include/System.h
include/Tracking.h
include/LocalMapping.h
include/LoopClosing.h
include/ORBextractor.h
include/ORBmatcher.h
include/FrameDrawer.h
include/Converter.h
include/MapPoint.h
include/KeyFrame.h
include/Atlas.h
include/Map.h
include/MapDrawer.h
include/Optimizer.h
include/Frame.h
include/KeyFrameDatabase.h
include/Sim3Solver.h
include/Viewer.h
include/ImuTypes.h
include/G2oTypes.h
include/CameraModels/GeometricCamera.h
include/CameraModels/Pinhole.h
include/CameraModels/KannalaBrandt8.h
include/OptimizableTypes.h
include/MLPnPsolver.h
include/GeometricTools.h
include/TwoViewReconstruction.h
include/SerializationUtils.h
include/Config.h
include/Settings.h)

if(BUILD_TEST)
   target_link_libraries(${PROJECT_NAME}
      ${OpenCV_LIBS}
      ${EIGEN3_LIBS}
      ${Pangolin_LIBRARIES}
      ${Boost_LIBRARIES}
      -lDBoW2
      -lg2o
      -lcrypto
   )
else()
   target_link_libraries(${PROJECT_NAME}
      ${OpenCV_LIBS}
      ${EIGEN3_LIBS}
      ${Boost_LIBRARIES}
      -lDBoW2
      -lg2o
      -lcrypto
   )
endif()

target_compile_options(${PROJECT_NAME} PRIVATE -Wall -O3 -Wno-Wdeprecated-declarations -Wno-Wunused-but-set-variable -Wno-Wsign-compare -Wno-Wreorder)
set_target_properties(${PROJECT_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_LIBRARY_OUTPUT_PATH})